// Author: wsfuyibing <682805@qq.com>
// Date: 2025-04-10

package database

// Config is a component used to connect specified database server.
type Config struct {
	Lifetime  int `yaml:"lifetime"`
	MaxActive int `yaml:"max_active"`
	MinIdle   int `yaml:"min_idle"`

	DsnCount int      `yaml:"-"`
	Driver   string   `yaml:"driver"`
	Dsn      []string `yaml:"dsn"`
}

func (o *Config) Defaulter() {
	if o.Lifetime == 0 {
		o.Lifetime = defaultLifetime
	}
	if o.MaxActive == 0 {
		o.MaxActive = defaultMaxActive
	}
	if o.MinIdle == 0 {
		o.MinIdle = defaultMinIdle
	}

	if o.Driver == "" {
		o.Driver = defaultDriver
	}
	o.DsnCount = len(o.Dsn)
}
